package com.java.module.user.controller.admin;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.java.common.lang.annotation.Log;
import com.java.common.lang.domain.AjaxResult;
import com.java.common.lang.enums.BusinessTypeEnum;
import com.java.common.utils.WebKit;
import com.java.module.user.domain.Message;
import com.java.module.user.service.IMessageService;
import com.java.common.utils.poi.ExcelUtil;
import com.java.common.lang.domain.page.TableDataInfo;

/**
 * 基础：消息Controller
 * 
 * @author Administrator
 * @date 2021-03-24
 */
@RestController("AdminMessageController")
@RequestMapping("/user/message")
public class MessageController {

    @Autowired
    private IMessageService messageService;

    /**
     * 查询基础：消息列表
     */
    @PreAuthorize("@ss.hasPermi('user:message:list')")
    @GetMapping("/list")
    public TableDataInfo list(Message message) {
        WebKit.startPage();
        List<Message> list = messageService.selectMessageList(message);
        return WebKit.getDataTable(list);
    }

    /**
     * 导出基础：消息列表
     */
    @PreAuthorize("@ss.hasPermi('user:message:export')")
    @Log(title = "基础：消息", businessType = BusinessTypeEnum.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Message message) {
        List<Message> list = messageService.selectMessageList(message);
        ExcelUtil<Message> util = new ExcelUtil<Message>(Message.class);
        return util.exportExcel(list, "message");
    }

    /**
     * 获取基础：消息详细信息
     */
    @PreAuthorize("@ss.hasPermi('user:message:query')")
    @GetMapping(value = "/{mid}")
    public AjaxResult getInfo(@PathVariable("mid") Long mid) {
        return AjaxResult.success(messageService.selectMessageById(mid));
    }

    /**
     * 新增基础：消息
     */
    @PreAuthorize("@ss.hasPermi('user:message:add')")
    @Log(title = "基础：消息", businessType = BusinessTypeEnum.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Message message) {
        return WebKit.toAjax(messageService.insertMessage(message));
    }

    /**
     * 修改基础：消息
     */
    @PreAuthorize("@ss.hasPermi('user:message:edit')")
    @Log(title = "基础：消息", businessType = BusinessTypeEnum.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Message message) {
        return WebKit.toAjax(messageService.updateMessage(message));
    }

    /**
     * 删除基础：消息
     */
    @PreAuthorize("@ss.hasPermi('user:message:remove')")
    @Log(title = "基础：消息", businessType = BusinessTypeEnum.DELETE)
    @DeleteMapping("/{mids}")
    public AjaxResult remove(@PathVariable Long[] mids) {
        return WebKit.toAjax(messageService.deleteMessageByIds(mids));
    }

}